﻿<Window x:Class="SEToolbox.Views.WindowImportModel"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:helix="http://helixtoolkit.codeplex.com"
        xmlns:commands="clr-namespace:SEToolbox.Services"
        xmlns:converters="clr-namespace:SEToolbox.Converters"
        xmlns:controls="clr-namespace:SEToolbox.Controls"
        ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" WindowStyle="ThreeDBorderWindow"
        Title="Import 3D Model" Height="440" Width="520" Icon="/SEToolbox;component/app.ico" Style="{StaticResource DefaultWindowStyle}"
        commands:DialogService.IsRegisteredView="True"
        commands:DialogCloser.DialogResult="{Binding CloseResult}"
        FocusManager.FocusedElement="{Binding ElementName=uxInitialElement}">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converters:ResouceToImageConverter x:Key="ResouceToImageConverter"/>
        <converters:EnumToResouceConverter x:Key="EnumToResouceConverter"/>
        <converters:BusyMouseConverter x:Key="BusyMouseConverter"/>
    </Window.Resources>
    <Window.Cursor>
        <Binding Path="IsBusy" Converter="{StaticResource BusyMouseConverter}"/>
    </Window.Cursor>
    <Grid>
        <Grid Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid Margin="0,0,0,8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Content="Model:" />
                <StackPanel Grid.Column="1" Orientation="Horizontal">
                    <TextBox Width="180" Text="{Binding Filename, Mode=TwoWay}" VerticalAlignment="Center" Name="uxInitialElement"/>
                    <Button ToolTip="Browse for Model" Command="{Binding Browse3DModelCommand}" VerticalAlignment="Center">
                        <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=folder}" />
                    </Button>
                </StackPanel>
                <Label Content="Type:" Grid.Row="1" />
                <ComboBox Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding Source={StaticResource ImportModelTypeEnum}}" SelectedValue="{Binding ClassType}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=., Converter={StaticResource EnumToResouceConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <!--Import To Ship/Station settings-->
                <Label Content="Calculation:" Grid.Row="2" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <ComboBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding Source={StaticResource ModelTraceVoxelEnum}}" SelectedValue="{Binding TraceType}" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=., Converter={StaticResource EnumToResouceConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <Label Content="Armor:" Grid.Row="3" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <ComboBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding Source={StaticResource ArmorTypeEnum}}" SelectedValue="{Binding ArmorType}" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=., Converter={StaticResource EnumToResouceConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <Label Content="Fill:" Grid.Row="4" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <CheckBox Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" IsChecked="{Binding FillObject}" Visibility="{Binding IsShip, Converter={StaticResource BooleanToVisibilityConverter}}" />

                <!--Import To Asteroid settings-->
                <Label Content="Ore Shell:" Grid.Row="2" Visibility="{Binding IsAsteroid, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <ComboBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding OutsideMaterialsCollection}" SelectedValue="{Binding OutsideStockMaterial}" DisplayMemberPath="DisplayName" Visibility="{Binding IsAsteroid, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <Label Content="Ore Inside:" Grid.Row="3" Visibility="{Binding IsAsteroid, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <ComboBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding InsideMaterialsCollection}" SelectedValue="{Binding InsideStockMaterial}" DisplayMemberPath="DisplayName" Visibility="{Binding IsAsteroid, Converter={StaticResource BooleanToVisibilityConverter}}"/>

                <Grid Grid.Row="0" Grid.Column="2" Grid.RowSpan="4">
                    <Border BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
                        <helix:HelixViewport3D >
                            <helix:DefaultLights/>
                            <helix:CoordinateSystemVisual3D/>
                            <ModelVisual3D Content="{Binding Model}"/>
                        </helix:HelixViewport3D>
                    </Border>
                </Grid>
                <StackPanel Grid.Row="5" Grid.ColumnSpan="3" Orientation="Horizontal">
                    <GroupBox Header="Original Size" MinWidth="120">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="65"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Width:" Margin="0,0,0,0" />
                            <TextBlock Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=OriginalModelSize.Width, StringFormat='{}{0:#,##0.00}'}" />
                            <TextBlock Text="Height:" Margin="0,0,0,0" Grid.Row="1" />
                            <TextBlock Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=OriginalModelSize.Height, StringFormat='{}{0:#,##0.00}'}" />
                            <TextBlock Text="Depth:" Margin="0,0,0,0" Grid.Row="2" />
                            <TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=OriginalModelSize.Depth, StringFormat='{}{0:#,##0.00}'}" />
                        </Grid>
                    </GroupBox>
                    <GroupBox Header="Scale" MinWidth="120">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <RadioButton Content="Multiply:" IsChecked="{Binding IsMultipleScale}" />
                            <TextBox Width="80" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource textBoxInError}">
                                <TextBox.Text>
                                    <Binding Path="MultipleScale" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
                                        <Binding.ValidationRules>
                                            <converters:RangeRuleD Min="0" Max="10000"/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                            <RadioButton Content="Max Length:" Grid.Row="1" IsChecked="{Binding IsMaxLengthScale}"/>
                            <TextBox Width="80" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource textBoxInError}" ToolTip="This specifies the longest dimension of the structure.">
                                <TextBox.Text>
                                    <Binding Path="MaxLengthScale" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
                                        <Binding.ValidationRules>
                                            <converters:RangeRuleD Min="5" Max="10240"/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                        </Grid>
                    </GroupBox>

                    <GroupBox Header="Approximate New Size" MinWidth="120" Margin="8,0,0,0">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="60"/>
                                <ColumnDefinition Width="60"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="1" Text="Blocks" HorizontalAlignment="Right" />
                            <TextBlock Grid.Column="2" Text="Meters" HorizontalAlignment="Right" />
                            <TextBlock Grid.Row="1" Text="Width:" Margin="0,0,0,0" VerticalAlignment="Center"/>
                            <TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelSize.Width, StringFormat='{}{0:#,##0}'}" />
                            <TextBlock Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelScale.X, StringFormat='{}{0:#,##0.0}'}" />
                            <TextBlock Grid.Row="2" Text="Height:" Margin="0,0,0,0" VerticalAlignment="Center" />
                            <TextBlock Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelSize.Height, StringFormat='{}{0:#,##0}'}" />
                            <TextBlock Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelScale.Y, StringFormat='{}{0:#,##0.0}'}" />
                            <TextBlock Grid.Row="3" Text="Depth:" Margin="0,0,0,0" VerticalAlignment="Center" />
                            <TextBlock Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelSize.Depth, StringFormat='{}{0:#,##0}'}" />
                            <TextBlock Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Path=NewModelScale.Z, StringFormat='{}{0:#,##0.0}'}" />
                        </Grid>
                    </GroupBox>
                </StackPanel>
                <StackPanel Grid.Row="6" Grid.ColumnSpan="3" Orientation="Horizontal">
                    <GroupBox Header="Position" MinWidth="120">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Label Content="X:" Margin="0,0,4,0" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" MinWidth="80" Width="100" VerticalAlignment="Center" Text="{Binding Path=Position.X, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <Label Content="Y:" Margin="0,0,4,0" Grid.Row="1" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" Grid.Row="1" MinWidth="80" Width="100" VerticalAlignment="Center" Text="{Binding Path=Position.Y, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <Label Content="Z:" Margin="0,0,4,0" Grid.Row="2"  VerticalAlignment="Center"/>
                            <TextBox Grid.Column="1" Grid.Row="2" MinWidth="80" Width="100" VerticalAlignment="Center" Text="{Binding Path=Position.Z, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </Grid>
                    </GroupBox>
                    <GroupBox Header="Orientation" MinWidth="120" Margin="8,0,0,0">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <RadioButton IsChecked="True" Content="Facing Player" Grid.ColumnSpan="2" />
                            <Label Content="Distance:" Grid.Row="2" />
                            <TextBox Grid.Column="1" MinWidth="80" Grid.Row="2" Text="{Binding BuildDistance}" ToolTip="Distance in front of Player in Meters." />
                        </Grid>
                    </GroupBox>
                </StackPanel>
            </Grid>
            <StackPanel Grid.Row="1" Orientation="Horizontal" Height="28" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                <Button Width="90" Command="{Binding CreateCommand}" Content="Create" IsDefault="True"/>
                <Button Margin="8,0,0,0" Width="90" Command="{Binding CancelCommand}" Content="Cancel" IsCancel="True"/>
            </StackPanel>
        </Grid>
        <controls:BusyIndicator Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" />
    </Grid>
</Window>
